package cn.zwx.goods.svc.service.impl;

import cn.zwx.goods.svc.domain.bo.AttrBO;
import cn.zwx.goods.svc.domain.entity.AttrEntity;
import cn.zwx.goods.svc.domain.entity.AttrValueEntity;
import cn.zwx.goods.svc.mapper.AttrMapper;
import cn.zwx.goods.svc.mapper.AttrValueMapper;
import cn.zwx.goods.svc.service.AttrService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangwenxue
 */
@Service
public class AttrServiceImpl implements AttrService {

    @Resource
    public AttrMapper attrMapper;

    @Resource
    private AttrValueMapper attrValueMapper;

    @Override
    public Integer selectCount(LambdaQueryWrapper<AttrEntity> queryWrapper) {
        return attrMapper.selectCount(queryWrapper).intValue();
    }

    @Override
    public List<AttrEntity> selectList(AttrBO attrBO) {
        return attrMapper.selectList(attrBO);
    }

    @Override
    public List<AttrValueEntity> selectAttrValueList(List<Long> attrIdList) {
        LambdaQueryWrapper<AttrValueEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(AttrValueEntity::getAttrId,attrIdList);
        return attrValueMapper.selectList(queryWrapper);
    }

    @Override
    public void insert(AttrEntity attrEntity) {
        attrMapper.insertSelective(attrEntity);
    }

    @Override
    public void batchInsertAttrVal(List<AttrValueEntity> valueEntityList) {
        attrValueMapper.batchInsert(valueEntityList);
    }

    @Override
    public AttrEntity selectById(Long attrId) {
        return attrMapper.selectById(attrId);
    }

    @Override
    public void deleteAttrValue(Long attrId) {
        LambdaQueryWrapper<AttrValueEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttrValueEntity::getAttrId,attrId);
        attrMapper.selectById(attrId);
    }

    @Override
    public void deleteAttrById(Long attrId) {
        attrMapper.deleteById(attrId);
    }
}
